//
//  UserInfoHelper.swift
//  PlayWithXMPP_Swift
//
//  Created by admin on 15/1/27.
//  Copyright (c) 2015年 com.zhongyan. All rights reserved.
//
import UIKit
let K_UserNameKey = "UserName"
let K_Password = "Password"
let K_LoginStatus = "LoginStatus"
class UserInfoHelper: NSObject {
    
    //取出上次登陆的UserName
    class func getUserName() -> NSString {
        if let userName:AnyObject = self.getObjectWithKey(K_UserNameKey)
        {
            return self.getObjectWithKey(K_UserNameKey) as NSString
        }
        return ""
    }
    class func saveUserName(username:NSString) {
        self.saveObjectWithKey(K_UserNameKey, object: username)
    }
    //取出上次登陆的password
    class func getPassword() -> NSString {
        if let password:AnyObject = self.getObjectWithKey(K_Password)
        {
            return self.getObjectWithKey(K_Password) as NSString
        }
        return ""
    }
    class func savePassword(password:NSString) {
        self.saveObjectWithKey(K_Password, object: password)
    }
    
    class func saveLoginStatus(status:Bool) {
        self.saveObjectWithKey(K_LoginStatus, object: status)
    }
    
    class func isLogin() -> Bool {
        if let status:AnyObject = self.getObjectWithKey(K_LoginStatus)
        {
            return status as Bool
        }
        return false
    }
    
    
    class func saveObjectWithKey(key:NSString, object:AnyObject?) {
        NSUserDefaults.standardUserDefaults().setObject(object, forKey: key)
    }
    class func getObjectWithKey(key:NSString) -> AnyObject?
    {
        return NSUserDefaults.standardUserDefaults().objectForKey(key)
    }
   
}
